import { request } from '@/utils/axios/axios'
import { AttrVo, Category, PageNationParams, PageNationResult } from '@/api/attr/type'
import { AttrGroupVo } from '@/api/attr-group/type'

enum API {
  // 查询分类信息
  CATEGORY_LIST = 'category',
  // 保存属性值
  ATTR = 'attr',
  // 查询属性值
  ATTR_LIST = 'attr/pagenationquery',
}

// 根据父id查询分类信息
export const categoryListRequest = (categoryId: number): Promise<Category[]> => {
  return request.get<number, Category[]>(API.CATEGORY_LIST + `/${categoryId}`)
}

// 保存属性值请求
export const addAttrRequest = (attrVo: AttrVo) => {
  return request.post<AttrVo>(API.ATTR, attrVo)
}
// 分页查询属性
export const queryAttrRequest = (pageNationParams: PageNationParams): Promise<PageNationResult> => {
  return request.get<PageNationParams, PageNationResult>(API.ATTR_LIST, {
    params: pageNationParams,
  })
}

// 根据分类id查询属性信息
// export const attrListRequest = (catalogId: number) => {
//   return request.get<number, AttrVo[]>(API.ATTR_LIST, { params: { catalogId: catalogId } })
// }

// 修改属性值请求
export const attrUpdateRequest = (attrVo: AttrVo) => {
  return request.put<AttrVo>(API.ATTR, attrVo)
}

// 删除属性请求
export const attrDeleteRequest = (attrIds: number[]): Promise<number> => {
  return request.delete<number[], number>(API.ATTR, { data: attrIds })
}
// 根据分类id查询属性分组
export const getAttrVoGroupByCatalogID = (catalogId: number): Promise<AttrGroupVo[]> => {
  return request.get<number, AttrGroupVo[]>(API.ATTR + `/${catalogId}`)
}
